<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */

class api extends PHPUnit_Framework_TestCase
{
    /*
     * author guzhengxiao
     */
    public function setUp()
    {
        $this->apiname = $_SERVER['argv'][0];
        include('api/basic.php');
        //$api_params; 应用级参数

        $task = uniqid();
        $basic_params = array(
            'to_api_v' => '2.0',
            'direct' => 'true',
            'task' => $task,
            'method' => $this->apiname,
        );
        $this->params = array_merge($api_params,$basic_params);
        $sign = base_certificate::gen_sign($this->params);
        $this->params['sign'] = $sign;
    }

    public function testApi(){
        $payment_id='17120716462914548256';
        //将订单支付状态同步到进销存,2018-1-10 by jeff
                $objOrders_items_model = app::get('b2c')->model('order_items');
                $objbills = app::get('ectools')->model('order_bills');
                $objbills_items = $objbills->getList('*', array('bill_id'=>$payment_id));
                $order_id = $objbills_items['0']['rel_id'];
                $_temp_param = array(
                    'method'=>'order.changePayStatus',
                    'params'=>array(
                        'orderCode'=>$order_id,
                        'pay_status'=>'1',
                    )
                );
                $erp_caller_obj = kernel::service('apioubao.rpc_erp_request');
                $result = $erp_caller_obj->call_api_oubao($_temp_param);   
                $result = json_decode($result,true);             
                // dump($result);exit;
                //未对异常进行处理，只打个日志
                logger::info("支付状态同步到进销存结果：".var_export($result,1));
        echo 111;exit;
        // $aGoods = app::get('b2c')->model('goods')->getList('spec_desc',array('goods_id'=>1776));
        $str = 9999999999;
        // print_r(gettype($str));exit;
        $arr=array(
            '2147483647'=>'aaa',
            '2147483648'=>'aaa',
            '222'=>'bbb'
        );
        dump(serialize($arr));exit;
        $json = '{"5":{"145757387460":{"private_spec_value_id":"145757387460","spec_value":"\u73b0\u8d27","spec_value_id":"60","spec_goods_images":""},"145757387461":{"private_spec_value_id":"145757387461","spec_value":"\u6837\u54c1","spec_value_id":"61","spec_goods_images":""}}}';
        dump(serialize(json_decode($json,true)));exit;
        $temp = 'a:1:{i:5;a:2:{i:145757387460;a:4:{s:21:"private_spec_value_id";s:12:"145757387460";s:10:"spec_value";s:6:"现货";s:13:"spec_value_id";s:2:"60";s:17:"spec_goods_images";s:0:"";}i:145757387461;a:4:{s:21:"private_spec_value_id";s:12:"145757387461";s:10:"spec_value";s:6:"样品";s:13:"spec_value_id";s:2:"61";s:17:"spec_goods_images";s:0:"";}}}';
        dump(unserialize($temp));exit;
        $json = '{"filter":{"order_id":["161130131618802"]},"app_id":"b2c","model":"b2c_mdl_orders","filetype":"csv","policy":"ftp","key":"export-1483446498","suffix":null}';
        $queue_params = json_decode($json,true);
        print_r($queue_params);
        // app::get('importexport')->model('task')->create_task('export',$_POST);
        kernel::single('importexport_tasks_runexport')->exec($queue_params);
        echo 'ok';exit;

        $json = '{"order_id":"161130131618802","real_ship_time":"2017-01-03 19:49:51"}';
        $m = app::get('b2c')->model('orders');
        $rowOrder = json_decode($json,true);
        print_r($rowOrder);
        $res = $m->save($rowOrder);
        print_r($res);
        exit;
        $headers = array(
            /*'Connection'=>$this->timeout,*/
            'Connection'=>'Close',
        );
        if($gzip){
            $headers['Content-Encoding'] = 'gzip';
        }

        $url = kernel::base_url(1).'/index.php/api';//'http://192.168.51.51/ecstore2.0/index.php/api';
        $core_http = kernel::single('base_httpclient');
        $response = $core_http->set_timeout(10)->post($url,$this->params,$headers);
        $data = json_decode($response,true);
        print_r($data);
    }
}
